﻿using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using DotNetDream.Common.BundleHelpers;

namespace Benecura.Interfaces.Web
{

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
               name: "SchedulingDefault",
               url: "Schedule",
               defaults: new { controller = "Home", action = "Index" }
           );

            routes.MapRoute(
                name: "Scheduling",
                url: "Schedule/{action}/{parentid}/{diff}",
                defaults: new { controller = "Schedule", action = "Index" }
            );
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

        protected void Application_Start()
        {
            //Register application name

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            //Register bundles
            BundleTable.Bundles.Add(new JsCoreBundle());
            BundleTable.Bundles.Add(new CssCoreBundle());
            /*BundleTable.Bundles.Add(new JsPluginBundle());
            BundleTable.Bundles.Add(new JsCustomBundle());
            BundleTable.Bundles.Add(new CssCustomBundle());
            BundleTable.Bundles.Add(new CssPluginBundle());*/

#if DEBUG
            foreach (var bundle in BundleTable.Bundles)
            {
                bundle.Transforms.Clear();
            }
#endif
            BundleTable.Bundles.EnableDefaultBundles();

            //Init the DB
            //Database.SetInitializer<BenecuraEntities>(new MyInitializer());
        }
    }
}